
using System.Windows.Navigation;


namespace AnalyStock.WPFPage;

public partial class NavigationPage : Page
{
    private ClassifyStockPage classifyStockPage;
    private LoadDataPage loadDataPage;
    private LookStockPage lookStockPage;
    private SelectStockPage selectStock;
    private TitlePage titlePage;

    public NavigationPage()
    {
        InitializeComponent();
        BtnGoBack.Click += BtnLoadChilderPage_Click;
        BtnLoadData.Click += BtnLoadChilderPage_Click;
        BtnClassifyStock.Click += BtnLoadChilderPage_Click;
        BtnLookStock.Click += BtnLoadChilderPage_Click;
        BtnSelectStock.Click += BtnLoadChilderPage_Click;
        BtnExit.Click += BtnLoadChilderPage_Click;
        LoadPages(ref titlePage);

    }

    private void BtnLoadChilderPage_Click(object sender, RoutedEventArgs e)
    {
        switch (sender as Button)
        {
            case { Name: nameof(BtnLoadData) }:
                LoadPages(ref loadDataPage);
                break;
            case { Name: nameof(BtnLookStock) }:
                LoadPages(ref lookStockPage);
                break;
            case { Name: nameof(BtnClassifyStock) }:
                LoadPages(ref classifyStockPage);
                break;
            case { Name: nameof(BtnSelectStock) }:
                LoadPages(ref selectStock);
                break;
            case { Name: nameof(BtnGoBack) }:
                LoadPages(ref titlePage);
                break;
            case { Name: nameof(BtnExit) }:
                ExitApp();
                break;
        }
    }

    private void ExitApp()
    {
        (Parent as NavigationWindow).Close();
    }

    private void LoadPages<T>(ref T t) where T : Page, new()
    {
        t ??= new T();
        MainFrame.NavigationService.Navigate(t);
    }



}